package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserWallet;
import com.qinggeng.project.system.service.IUserWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户钱包Controller
 *
 * @author qinggeng
 * @date 2020-06-26
 */
@RestController
@RequestMapping("/system/wallet")
public class UserWalletController extends BaseController
{
    @Autowired
    private IUserWalletService userWalletService;

    /**
     * 查询用户钱包列表
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserWallet userWallet)
    {
        startPage();
        List<UserWallet> list = userWalletService.selectUserWalletList(userWallet);
        return getDataTable(list);
    }

    /**
     * 导出用户钱包列表
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:export')")
    @Log(title = "用户钱包", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserWallet userWallet)
    {
        List<UserWallet> list = userWalletService.selectUserWalletList(userWallet);
        ExcelUtil<UserWallet> util = new ExcelUtil<UserWallet>(UserWallet.class);
        return util.exportExcel(list, "wallet");
    }

    /**
     * 获取用户钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:query')")
    @GetMapping(value = "/{walletId}")
    public AjaxResult getInfo(@PathVariable("walletId") Long walletId)
    {
        return AjaxResult.success(userWalletService.selectUserWalletById(walletId));
    }

    /**
     * 新增用户钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:add')")
    @Log(title = "用户钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserWallet userWallet)
    {
        return toAjax(userWalletService.insertUserWallet(userWallet));
    }

    /**
     * 修改用户钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:edit')")
    @Log(title = "用户钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserWallet userWallet)
    {
        return toAjax(userWalletService.updateUserWallet(userWallet));
    }

    /**
     * 删除用户钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:remove')")
    @Log(title = "用户钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{walletIds}")
    public AjaxResult remove(@PathVariable Long[] walletIds)
    {
        return toAjax(userWalletService.deleteUserWalletByIds(walletIds));
    }
}
